package com.qf.bank.cardinfoprovider.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.bank.cardinfoapi.po.CardInfo;
import com.qf.bank.cardinfoapi.vo.CardInfoVo;
import com.qf.bank.cardinfoprovider.service.CardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lwf
 * @since 2019-12-04
 */
@RestController
public class CardInfoController{
    @Autowired
    private CardInfoService cardInfoService;

    /**
     * 分页查询
     * @param current
     * @param size
     * @return
     */
//    @RequestMapping(value = "/", method = RequestMethod.GET)
//    public IPage<CardInfo> page(@RequestParam int current, @RequestParam int size) {
//        IPage<CardInfo> page = cardInfoService.page(new Page<>(current, size));
//        return page;
//    }

    /**
     * 分页查询
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public IPage<CardInfo> page(@RequestBody CardInfoVo cardInfoVo) {
        return cardInfoService.pageWithCondition(cardInfoVo);
    }
    /**
     * 根据用户名获取用户所有的银行卡信息
     * @param userName
     * @return
     */
    @RequestMapping(value = "/name", method = RequestMethod.GET)
    public List<CardInfo> getByuserName(@RequestBody String userName) {
        List<CardInfo> byuserName = cardInfoService.getByuserName(userName);
        return byuserName;
    }


    /**
     * 增加一条银行卡数据
     * @param cardInfo
     * @return
     */
    @RequestMapping(value = "/",method = RequestMethod.POST)
    public Boolean getInsert(@RequestBody CardInfo cardInfo){
        boolean byId = cardInfoService.saveOrUpdate(cardInfo);
        return byId;
    }

    /**
     * 删除一条银行卡信息
     * @param cardId
     * @return
     */
    @RequestMapping(value = "/{cardId}", method = RequestMethod.DELETE)
    public Boolean deleteById(@PathVariable(value = "cardId") int cardId) {
        boolean removeById = cardInfoService.removeById(cardId);
        return removeById;
    }

    /**
     * 修改一条银行卡信息
     * @param cardInfo
     * @return
     */
    @RequestMapping(value = "/",method = RequestMethod.PUT)
    public Boolean updateById(@RequestBody CardInfo cardInfo){
        boolean updateById = cardInfoService.updateById(cardInfo);
        return updateById;
    }


}
